<?php
session_start();
require_once "config.php";
require_once "Includes/conexion.class.php";
include "Includes/soloFun_Generales.php";
include "Includes/solotrn_sesion.php";

if (!empty($_REQUEST["hidId"]) && !empty($_REQUEST["CboNodo"])) {
    $err = 0;
    $arrQueries = array();

    $desIni = $_REQUEST["perfilDesIni"];
    $des = $_REQUEST["perfilDes"];
    $co_perf = $_REQUEST["valcboperfil"];
    if($desIni != $des){
        $tipo = "UPDATE";
        $tabla = "solotb_perfil";
        $strSql = "$tipo $tabla SET ds_perf = '$des' WHERE co_perf = $co_perf";
        array_push($arrQueries, $strSql);
        array_push($arrQueries, crearQueryLog($tabla, $tipo, $strSql));
    }

    //Borrar el Perfil Actual
    $tipo = "DELETE";
    $tabla = "solotb_perfil_modulo";
    $strSql = "$tipo from $tabla where nodo = " . $_REQUEST["CboNodo"];
    $strSql .= " and co_perf= $co_perf";
    
    array_push($arrQueries, $strSql);
    array_push($arrQueries, crearQueryLog($tabla, $tipo, $strSql));

    $oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"], 
            $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);

    //if(!$oConexion->EjecutarQuery($strSql)) {
    if(!$oConexion->EjecutarTransaccion($arrQueries)){
        $strERROR = 1;
        $err=0;
        echo $oConexion->getErrorMessage();
        $oConexion->Cerrar();
    }else {
        $oConexion->Cerrar();
        foreach ($_REQUEST["transaccion"] as $key) {
            $arrSplit = preg_split("[\@]", $key);
            $tipo = "INSERT";
            $tabla = "solotb_perfil_modulo";
            $strSql = "$tipo into $tabla values (";
            $strSql .= $_REQUEST["valcboperfil"] . ",";
            $strSql .= $arrSplit[0] . ",";
            $strSql .= $arrSplit[1] . ",";
            $strSql .= $_REQUEST["CboNodo"] . ")";
            //echo "<br>strSql = " . $strSql;
            $arrQueries = array();
            array_push($arrQueries, $strSql);
            array_push($arrQueries, crearQueryLog($tabla, $tipo, $strSql));

            $oConexion = new Conexion($WORKFLOW["motor_base"], $WORKFLOW["db_usuario"], $WORKFLOW["db_password"], 
                    $WORKFLOW["basedatos"], $WORKFLOW["servidor"], $WORKFLOW["flags"], $WORKFLOW["encoding"]);
            //$oConexion->EjecutarQuery($strSql);
            $oConexion->EjecutarTransaccion($arrQueries);
            $oConexion->Cerrar();
        }
    }
//'	  response.end
    header ("Location: solotrn_ModificarPerfil.php?SoloError=0&CmbPerfil=" . $_REQUEST["hidId"] . "&CboNodo=".$_REQUEST["CboNodo"]);
}
?>